package wei.xinya.pattern.behavioral.observer;

import java.util.Observable;

public class ObserverPatternDemo extends Observable {
    public static void main(String[] args) {
        ObserverPatternDemo observable = new ObserverPatternDemo();

        observable.addObserver(((o, arg) -> System.out.println("Binary String: " + Integer.toBinaryString((Integer) arg))));
        observable.addObserver(((o, arg) -> System.out.println("Octal String: " + Integer.toOctalString((Integer) arg))));
        observable.addObserver(((o, arg) -> System.out.println("Hex String: " + Integer.toHexString((Integer) arg).toUpperCase())));

        System.out.println("First state change: 15");
        observable.setChanged();
        observable.notifyObservers(15);

        System.out.println("Second state change: 10");
        observable.setChanged();
        observable.notifyObservers(10);
    }
}
